package com.longrise.android.by.javascriptInterface;

import android.view.View;
import android.webkit.JavascriptInterface;

import com.longrise.android.byjk.model.ShareParams;
import com.longrise.android.by.activity.BYWebActivity;

/**
 * Created by godliness on 2017/3/9.
 */

public class ProComInterface {

    private BYWebActivity mCxt;

    public ProComInterface(BYWebActivity cxt) {
        mCxt = cxt;
    }

    @JavascriptInterface
    public void shareParams(String title, String content, String url, String iconUrl) {
        try {
            ShareParams shareParams = new ShareParams();
            shareParams.mUrl = url;
            shareParams.mContent = content;
            shareParams.mTitle = title;
            shareParams.mHeadUrl = iconUrl;
            mCxt.showShareDialog(shareParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @JavascriptInterface
    public void isShare(final boolean isShare) {
        mCxt.mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCxt.mShare.setVisibility(isShare ? View.VISIBLE : View.GONE);
            }
        });
    }

    @JavascriptInterface
    public void loadFinish(){
        mCxt.mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCxt.isLoading(false);
            }
        });
    }
}
